<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;

class ParamValue extends Model
{
    protected $fillable = ['name', 'type_id'];

    protected static function boot()
    {
        parent::boot();
        static::saved(function ($param) {
            $param->type->updateCount();
            // 更新缓存数据
            Cache::forever('params', ParamType::with('params')->get());
        });
    }

    public function type()
    {
        return $this->belongsTo(ParamType::class);
    }
}
